package 多线程.多线程;

public class InterRuputThread {

    private static class MyThread implements Runnable{

        @Override
        public void run() {
            while (!Thread.interrupted()){
                System.out.println(Thread.currentThread().getName()+"还活着");
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    System.err.println("有危险");
                    break;
                }
            }

            System.out.println("游戏结束");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread mt = new MyThread();
        Thread thread = new Thread(mt,"奥巴马");
        System.out.println("奥巴马在对线");
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }
}
